package com.example.bbs.controller;


//import com.example.bbs.client.DemoService;
import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A;
import com.example.bbs.config.BbsProperties;
import com.example.bbs.dto.UserInfo;
import com.example.bbs.mapper.UserInfoMapper;
import com.example.bbs.pojo.Result;
import com.example.bbs.pojo.User;
import com.example.bbs.utils.ThreadLocalUtil;
import com.fasterxml.jackson.annotation.JsonFormat;

import com.hmall.api.client.DemoService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.beans.Transient;
import java.util.Map;

@ApiModel(value = "用户信息", description = "包含用户的基本信息")
@RestController
public class UserInfoController {
    @Autowired
    private DemoService demoService;

    @Autowired
    private UserInfoMapper userInfoMapper;

//    @Autowired
    private final  BbsProperties bbsProperties;

    public UserInfoController(BbsProperties bbsProperties) {
        this.bbsProperties = bbsProperties;
    }


    @ApiOperation("添加商品到购物车")
    //查询用户信息
    @GetMapping("/userinfo")
    public Result selectUserInfoData() {
        System.out.println("这里sssssssssssss" + demoService.getUser());
        System.out.println(bbsProperties);
        //获取用户名
        Map<String, Object> map = ThreadLocalUtil.get();
//        String username = "admin";
        String username = (String) map.get("username");
        return Result.success(userInfoMapper.selectUserInfoData(username));
    }

    @PostMapping("/userinfo")
    public Result update(@JsonFormat UserInfo userInfo) {

//        System.out.println(userInfo);
        //获取用户名
        Map<String, Object> map = ThreadLocalUtil.get();
        String username = (String) map.get("username");
        userInfo.setUsername(username);
        userInfoMapper.updateUserInfo(userInfo);
        return Result.success();
    }


}
